class Solution:
    def maximumScore(self, nums: list, multipliers: list) -> int:
        def func(nums, multipliers, i, j, memo):
            if (i, j) in memo:
                return memo[(i, j)]
            if i == len(multipliers):
                return 0
            res = max(
                nums[j] * multipliers[i] +
                func(nums, multipliers, i + 1, j + 1, memo),
                nums[len(nums) - i - 1 + j] * multipliers[i] +
                func(nums, multipliers, i + 1, j, memo))
            memo[(i, j)] = res
            return res

        return func(nums, multipliers, 0, 0, {})